package nl.ceasaro.jeslee.core.service;

import nl.ceasaro.jeslee.core.dao.GenericDAO;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: cees
 * Date: Dec 2, 2007
 * Time: 12:17:38 AM
 * <p/>
 * <p>
 * An abstract Service all service in this project should extends this service.
 * </p>
 */
@Service
public abstract class AbstractService<T, ID extends Serializable>
{
   public abstract GenericDAO<T, ID> getDAO();

   /**
    *
    * @param id the id of the returned instance
    * @return the instance bound to the specified id.
    */
   public T getById(ID id)
   {
      return getDAO().get(id);
   }

   /**
    *
    * @return all instances of T
    */
   public List<T> findAll()
   {
      return getDAO().findAll();
   }

   /**
    * saves a new instance
    * @param instance the instance to save
    * @return the ID of the stored instance
    */
   public ID save(T instance)
   {
      return getDAO().save(instance);
   }

   /**
    * updates an instance
    *
    * @param instance the instance to update
    */
   public void update(T instance)
   {
      getDAO().update(instance);
   }

   /**
    * deletes an instance
    *
    * @param instance the instance to delete
    */
   public void delete(T instance)
   {
      getDAO().delete(instance);
   }
}
